<?php
/**
 * Author: DefinitlyEvil
 * Created at: 2020/4/17 0:46
 */

namespace App\Tools;




use AlibabaCloud\Client\AlibabaCloud;

class SMS
{
    public static function sendCode($phone, $code) {
        ECSTools::initClient();
        $response = AlibabaCloud::rpc()->product('Dysmsapi')
            ->scheme('https') // https | http
            ->version('2017-05-25')
            ->action('SendSms')
            ->method('POST')
            ->host('dysmsapi.aliyuncs.com')
            ->regionId('default')
            ->options([
                'query' => [
                    'RegionId' => "default",
                    'PhoneNumbers' => $phone,
                    'SignName' => getenv('ALIYUN_SMS_SIGN'),
                    'TemplateCode' => getenv('ALIYUN_SMS_TEMPLATE_ID'),
                    'TemplateParam' => json_encode([ 'code' => $code ])
                ],
            ])
            ->connectTimeout(5)
            ->timeout(5)
            ->request();

        trigger_error(print_r($response, true));
    }
}